Skip to content

Convert matplotlib stairs plots to plotly step lines - #5698

Merged
camdecoster merged 10 commits into
plotly:mainfrom
robertoffmoura:rm/fix-stairs-plot
Oct 9, 2026
Merged

camdecoster merged 10 commits into
plotly:mainfrom
robertoffmoura:rm/fix-stairs-plot

Conversation

@robertoffmoura

@robertoffmoura robertoffmoura commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

mpl_to_plotly currently drops plt.stairs plots entirely. Matplotlib's stairs creates a StepPatch artist, which the exporter treats as a generic path, and the renderer only handles bar-chart paths, so the stairs plot is skipped with the warning "I found a path object that I don't think is part of a bar chart. Ignoring." The converted figure has zero traces.

Fix: draw_path now recognizes StepPatch artists and draws them as a line trace:

  • the StepPatch's path vertices already describe the horizontal/vertical step outline, so they're used directly (consecutive duplicates removed)
  • line styling (color, width, dash) comes from the patch's edge properties

Snippet to reproduce:

import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
import numpy as np
import plotly.tools as tls

x = np.linspace(0, 10, 20)

fig, ax = plt.subplots()
ax.stairs(np.sin(x))
fig.savefig("stairs_mpl.png")

p = tls.mpl_to_plotly(fig)
p.write_image("stairs_plotly.png") 
matplotlib plotly before plotly after
stairs_mpl stairs_plotly stairs_plotly_after

@robertclaus

Copy link
Copy Markdown

@robertoffmoura just a heads up that we saw your PRs come in. We're still planning to review them when we have a chance!

@robertoffmoura
robertoffmoura force-pushed the rm/fix-stairs-plot branch 2 times, most recently from 1b513c9 to da4375f Compare September 3, 2026 11:36
@emilykl
emilykl requested review from camdecoster and removed request for emilykl September 4, 2026 20:10
@emilykl emilykl removed their assignment Sep 4, 2026
@robertoffmoura

Copy link
Copy Markdown
Contributor Author

Rebased, solved merge conflict, and added changelog entry

@robertoffmoura

Copy link
Copy Markdown
Contributor Author

Fixed some issues related to dates and NaN values. This is now ready for review.

@camdecoster camdecoster self-assigned this Oct 8, 2026
@camdecoster

Copy link
Copy Markdown
Contributor

@robertoffmoura given the pace of your changes to this converter, what do you think of splitting this out of plotly.py into a separate repo that could be community maintained? There aren't that many interface points between the two, so I don't think that it would be too difficult. I'm happy to have a call or move to email if you're interested and would like to discuss the idea.

@camdecoster
camdecoster merged commit cb82f63 into plotly:main Oct 9, 2026
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants